//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.base.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.live.base.service.ILiveExamClassService;
import com.ruoyi.live.base.domain.LiveExamClass;
import com.ruoyi.live.base.mapper.LiveExamClassMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LiveExamClassServiceImpl extends ServiceImpl<LiveExamClassMapper, LiveExamClass> implements ILiveExamClassService {
    public LiveExamClassServiceImpl() {
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveRelatedClass(List<LiveExamClass> list) {
        if(CollectionUtil.isEmpty(list)) {
            return false;
        }
        LiveExamClass first = CollectionUtil.get(list, 0);
        Long examId = first.getExamId();

        QueryWrapper deleteWrapper = new QueryWrapper();
        deleteWrapper.eq("exam_id", examId);
        this.getBaseMapper().delete(deleteWrapper);

        return this.saveBatch(list);
    }
}